﻿using System;
using System.Reflection;
using System.Configuration;
using JKF.DataModule.IDAL;
namespace JKF.DataModule.DALFactory
{
    /// <summary>
    /// 抽象工厂模式创建DAL。
    /// web.config 需要加入配置：(利用工厂模式+反射机制+缓存机制,实现动态创建不同的数据层对象接口)  
    /// DataCache类在导出代码的文件夹里
    /// <appSettings>  
    /// <add key="DAL" value="JKF.Entities.SQLServerDAL" /> (这里的命名空间根据实际情况更改为自己项目的命名空间)
    /// </appSettings> 
    /// </summary>
    public sealed class DataAccess_Other
    {
        //private static readonly string AssemblyPath = ConfigurationManager.AppSettings["DAL"];可以在配置文件中读取
        private static readonly string AssemblyPath = "JKF.DataModule";//动态库文件
        private static readonly string NameSpase = "JKF.DataModule.SqlServerDAL";//命名空间
        /// <summary>
        /// 创建对象或从缓存获取
        /// </summary>
        public static object CreateObject(string AssemblyPath, string ClassNamespace)
        {
            object objType = DataCache.GetCache(ClassNamespace);//从缓存读取
            if (objType == null)
            {
                try
                {
                    objType = Assembly.Load(AssemblyPath).CreateInstance(ClassNamespace);//反射创建
                    DataCache.SetCache(ClassNamespace, objType);// 写入缓存
                }
                catch (Exception ex)
                {
                    throw new Exception("反射创建数据处出错！", ex);
                }
            }
            return objType;
        }
        /// <summary>
        /// 创建dalGIFT_TYPE数据层接口
        /// </summary>
        public static JKF.DataModule.IDAL.IdalGIFT_TYPE CreatedalGIFT_TYPE()
        {

            string ClassNamespace = NameSpase + ".dalGIFT_TYPE";
            object objType = CreateObject(AssemblyPath, ClassNamespace);
            return (JKF.DataModule.IDAL.IdalGIFT_TYPE)objType;
        }

        /// <summary>
        /// 创建dalGIFTS数据层接口
        /// </summary>
        public static JKF.DataModule.IDAL.IdalGIFTS CreatedalGIFTS()
        {

            string ClassNamespace = NameSpase + ".dalGIFTS";
            object objType = CreateObject(AssemblyPath, ClassNamespace);
            return (JKF.DataModule.IDAL.IdalGIFTS)objType;
        }


        /// <summary>
        /// 创建dalPOINT_EXCHANGE数据层接口
        /// </summary>
        public static JKF.DataModule.IDAL.IdalPOINT_EXCHANGE CreatedalPOINT_EXCHANGE()
        {

            string ClassNamespace = NameSpase + ".dalPOINT_EXCHANGE";
            object objType = CreateObject(AssemblyPath, ClassNamespace);
            return (JKF.DataModule.IDAL.IdalPOINT_EXCHANGE)objType;
        }


        /// <summary>
        /// 创建dalDIC_AREA数据层接口
        /// </summary>
        public static JKF.DataModule.IDAL.IdalDIC_AREA CreatedalDIC_AREA()
        {

            string ClassNamespace = NameSpase + ".dalDIC_AREA";
            object objType = CreateObject(AssemblyPath, ClassNamespace);
            return (JKF.DataModule.IDAL.IdalDIC_AREA)objType;
        }


        /// <summary>
        /// 创建dalDIC_GENDER数据层接口
        /// </summary>
        public static JKF.DataModule.IDAL.IdalDIC_GENDER CreatedalDIC_GENDER()
        {

            string ClassNamespace = NameSpase + ".dalDIC_GENDER";
            object objType = CreateObject(AssemblyPath, ClassNamespace);
            return (JKF.DataModule.IDAL.IdalDIC_GENDER)objType;
        }


        /// <summary>
        /// 创建dalDIC_POINT数据层接口
        /// </summary>
        public static JKF.DataModule.IDAL.IdalDIC_POINT CreatedalDIC_POINT()
        {

            string ClassNamespace = NameSpase + ".dalDIC_POINT";
            object objType = CreateObject(AssemblyPath, ClassNamespace);
            return (JKF.DataModule.IDAL.IdalDIC_POINT)objType;
        }


        /// <summary>
        /// 创建dalSYS_USER_SHOP数据层接口
        /// </summary>
        public static JKF.DataModule.IDAL.IdalSYS_USER_SHOP CreatedalSYS_USER_SHOP()
        {

            string ClassNamespace = NameSpase + ".dalSYS_USER_SHOP";
            object objType = CreateObject(AssemblyPath, ClassNamespace);
            return (JKF.DataModule.IDAL.IdalSYS_USER_SHOP)objType;
        }


        /// <summary>
        /// 创建dalSWING_CARD数据层接口
        /// </summary>
        public static JKF.DataModule.IDAL.IdalSWING_CARD CreatedalSWING_CARD()
        {

            string ClassNamespace = NameSpase + ".dalSWING_CARD";
            object objType = CreateObject(AssemblyPath, ClassNamespace);
            return (JKF.DataModule.IDAL.IdalSWING_CARD)objType;
        }


        /// <summary>
        /// 创建dalSHOP数据层接口
        /// </summary>
        public static JKF.DataModule.IDAL.IdalSHOP CreatedalSHOP()
        {

            string ClassNamespace = NameSpase + ".dalSHOP";
            object objType = CreateObject(AssemblyPath, ClassNamespace);
            return (JKF.DataModule.IDAL.IdalSHOP)objType;
        }


        /// <summary>
        /// 创建dalPOINT_LOG数据层接口
        /// </summary>
        public static JKF.DataModule.IDAL.IdalPOINT_LOG CreatedalPOINT_LOG()
        {

            string ClassNamespace = NameSpase + ".dalPOINT_LOG";
            object objType = CreateObject(AssemblyPath, ClassNamespace);
            return (JKF.DataModule.IDAL.IdalPOINT_LOG)objType;
        }

        /// <summary>
        /// 创建dalDIC_DISEASE数据层接口
        /// </summary>
        public static JKF.DataModule.IDAL.IdalDIC_DISEASE CreatedalDIC_DISEASE()
        {

            string ClassNamespace = NameSpase + ".dalDIC_DISEASE";
            object objType = CreateObject(AssemblyPath, ClassNamespace);
            return (JKF.DataModule.IDAL.IdalDIC_DISEASE)objType;
        }

        /// <summary>
        /// 创建dalPOINT_EXCHANGE_ITEM数据层接口
        /// </summary>
        public static JKF.DataModule.IDAL.IdalPOINT_EXCHANGE_ITEM CreatedalPOINT_EXCHANGE_ITEM()
        {

            string ClassNamespace = NameSpase + ".dalPOINT_EXCHANGE_ITEM";
            object objType = CreateObject(AssemblyPath, ClassNamespace);
            return (JKF.DataModule.IDAL.IdalPOINT_EXCHANGE_ITEM)objType;
        }


        /// <summary>
        /// 创建dalPermission数据层接口
        /// </summary>
        public static JKF.DataModule.IDAL.IdalPermission CreatedalPermission()
        { 
            string ClassNamespace = NameSpase + ".dalPermission";
            object objType = CreateObject(AssemblyPath, ClassNamespace);
            return (JKF.DataModule.IDAL.IdalPermission)objType;
        }
    }
}